;;;
;;;
;;;	Author:	Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;		COPYRIGHT: 2/25/2010
;;;		   EDITED: 2/25/2010
;;;
(defun c:underline ()
  (IF ukword NIL (LOAD "ukword" "\nFile UKWORD.LSP not loaded! "))
  (SETQ ul_type (ukword 1 "Line Text" "Type of underline [Line/Text]" (IF ul_type ul_type "Line")))
  (SETQ text_ss (ssget '((0 . "TEXT"))))
  (IF text_ss
    (PROGN
      (SETQ cnt 0)
      (SETQ mod_this_ent NIL)
      (WHILE (< cnt (SSLENGTH text_ss))
	(SETQ this_ent (ENTGET (SSNAME text_ss cnt)))
        (COND
          ((AND
             (EQ ul_type "Text")
             (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "%%U*")
             (NOT (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "%%U*%%U*"))
           )
           (SETQ this_ent (SUBST (CONS 1 (STRCAT (CDR (ASSOC 1 this_ent)) "%%U"))(ASSOC 1 this_ent)this_ent))
           (SETQ mod_this_ent T))
          ((AND
             (EQ ul_type "Text")
             (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "*%%U*")
             (NOT (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "*%%U*%%U*"))
           )
           (SETQ this_ent (SUBST (CONS 1 (STRCAT "%%U" (CDR (ASSOC 1 this_ent))))(ASSOC 1 this_ent)this_ent))
           (SETQ mod_this_ent T))
          ((AND
             (NOT (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "*%%U*"))
             (EQ ul_type "Text")
           )
           (SETQ this_ent (SUBST (CONS 1 (STRCAT "%%U" (CDR (ASSOC 1 this_ent)) "%%U"))(ASSOC 1 this_ent)this_ent))
           (SETQ mod_this_ent T))
          ((EQ ul_type "Line")
           (IF (WCMATCH (STRCASE (CDR (ASSOC 1 this_ent))) "%%U*")
             (PROGN
               (SETQ this_ent (SUBST (CONS 1 (SUBSTR (CDR (ASSOC 1 this_ent)) 4))(ASSOC 1 this_ent) this_ent))
               (ENTMOD this_ent)
               (ENTUPD (SSNAME text_ss cnt))
             )
           )
           (SETQ ul_box (TEXTBOX this_ent));point pair bounding box offset from justification point, lower left and upper right
           (SETQ ul_ang    (CDR (ASSOC 50 this_ent));rotation angle, optional, missing = 0
                 ul_txtoff (* 0.1 (CDR (ASSOC 40 this_ent)));arbitrary offset value used to tweak calculated point results
                 ul_ins_10 (CDR (ASSOC 10 this_ent));justification point when 72 and 73 are zero or missing
                 ul_ins_11 (CDR (ASSOC 11 this_ent));justification point when 72 and 73 are NOT zero or missing
                 ul_ins_71 (CDR (ASSOC 71 this_ent));0=default, 2=mirrored in X, 4=mirrored in Y
                 ul_ins_72 (CDR (ASSOC 72 this_ent));0=left, 1=center, 2=right, 3=aligned, 4=middle, 5=fit
                 ul_ins_73 (CDR (ASSOC 73 this_ent));3=top, 2=middle, 1=bottom, 0=baseline
           )
              (IF (OR (NOT ul_ang)(EQ ul_ang 0))
                (SETQ ul_ang 0.0)
              )
              (SETQ line_pt1 (list (+(CAAR ul_box)(CAR ul_ins_10)(- 0 (* 1.5 ul_txtoff)))(+(CADAR ul_box)(CADR ul_ins_10)(- 0 (* 4.0 ul_txtoff)))0.0)
                    line_pt  (INTERS
                               line_pt1
                               (POLAR line_pt1 ul_ang 10.0)
                               ul_ins_10
                               (POLAR ul_ins_10 (+ ul_ang (* 1.5 PI)) 10.0)
                               nil
                             )
                    line_pt2 (POLAR line_pt1 ul_ang (+(DISTANCE (LIST (CAAR ul_box)(CADAR ul_box))(LIST (CAADR ul_box)(CADADR ul_box)))(* 2.5 ul_txtoff)))
              )
              (ENTMAKE (LIST (CONS 0 "LINE")(ASSOC 8 this_ent)(CONS 10 line_pt1)(CONS 11 line_pt2)))
             (SETQ mod_this_ent NIL))
          (T
           (SETQ mod_this_ent NIL))
        )
        (IF mod_this_ent
          (PROGN
            (ENTMOD this_ent)
            (ENTUPD (SSNAME text_ss cnt))
          )
        )
	(SETQ cnt (1+ cnt))
      )
    )
  )
  (PRINC)
)